<?php

/**
 * Created by PhpStorm.
 * User: shwy
 * Date: 2017/9/8
 * Time: 9:52
 * 预警管理相关接口
 */
class warning extends CI_Controller
{


    public function __construct()
    {
        parent::__construct();
        $this->load->model('warning_model');

    }

    //用户筛选接口
    public function search(){


        $argc = [];

        //开始时间
        if(isset($_GET['startTime'])  && $_GET['startTime']){
            $argc += [
                'createTime >'=> strtotime($_GET['startTime']),
            ];
        }

        //结束时间
        if(isset($_GET['endTime'])  && $_GET['endTime']){
            $argc += [
                'createTime <'=> strtotime($_GET['endTime']),
            ];
        }

        //商品一级分类
        if(isset($_GET['category']) && $_GET['category'] !='' && $_GET['category'] != 'null'){
            $argc += [
                'category' => $_GET['category']
            ];
        }

        //预警状态
        if (isset($_GET['status']) && $_GET['status'] != '' && $_GET['status'] != 'null') {
            if ($_GET['status'] == 0) {
                //查询待审核的
                $argc += [
                    'status ' => 0
                ];
            } else {
                //查询已审核的
                $argc += [
                    'status !=' => 0
                ];
            }

        }


        //搜索用户名
        if(isset($_GET['search']) && $_GET['search']){
            $searchArg = [
                'field' => 'name',
                'arg'=> $_GET['search'],
                'side' => 'both'
            ];
        }else{
            $searchArg = '';
        }



        $page_num = $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = ''; //初始数据
        $page = ($this->input->get('page')); //获取页码数量
        if(!$page){
            $num = 1;
            $start_position = ($num - 1) * $page_num;
        }else{
            $start_position = ($page - 1) * $page_num;
        }

        if(!$argc){
            $argc = 0;
        }


//        echo '<pre>';
//        print_r($argc);
//        die;


        if($searchArg){
            $data = $this->warning_model->search('*',$argc,$searchArg,$page_num,$start_position);
        }else{
            $data = $this->warning_model->page('warning',$argc,$page_num,$start_position);
        }


        $data['pageNum'] = $page_num;
        $data['this_page'] = $page;

        //搜索





//        echo '<pre>';
//        print_r($result);
//        die;
        echo json_encode($data,JSON_UNESCAPED_UNICODE);

    }


}










































